      subroutine ellip (niph,tsde,tsth,trra,traz,te)
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c     elltab calculates the ellipticity travel time correction 
c       by table lookup.
c
c     originally written by Lane Johnson; 
c     modified by Lind Gee to include ScS
c
c     input --
c       iph     option parameter for type of phase
c                1 = p wave
c                2 = s wave
c                3 = scs wave
c       sde     depth of source (km)
c       sth     latitude of source (deg n>0)
c       rra     range of receiver from source (deg)
c       raz     azimuth of receiver with respect to source
c
c     output --
c       te      ellipticity time correction (sec)
c
c     notes  --
c          te should be added to calculated times in order to obtain
c     times for an elliptical earth, or subtracted from observed times
c     in order to obtain times for a spherical earth.
c          the tables included are for the iaspei91 velocity model.
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
      real*4 sd(8),p0(21,8),p1(21,8),p2(21,8)
      real*4 s0(21,8),s1(21,8),s2(21,8)
      real*4 scs0(21,8),scs1(21,8),scs2(21,8)
c
      data tpi,radi,ell/6.283185306,57.29577951,0.99327733/
c
      data rde,rmi,rma/5.0,0.0,100.0/
      data (sd(i),i=1,8)/0.0,35.0,50.0,100.0,200.0,300.0,500.0,700.0/
      data (p0(i,1),i=1,21)/+0.00,-0.18,-0.32,-0.46,-0.56,-0.62,-0.66,
     1    -0.66,-0.66,-0.64,-0.62,-0.58,-0.54,-0.51,-0.48,-0.45,-0.44,
     2    -0.45,-0.47,-0.51,-0.55/
      data (p1(i,1),i=1,21)/+0.00,-0.01,-0.05,-0.10,-0.16,-0.21,-0.30,
     1    -0.33,-0.37,-0.39,-0.40,-0.39,-0.35,-0.30,-0.22,-0.12,-0.01,
     2    +0.12,+0.24,+0.38,+0.46/
      data (p2(i,1),i=1,21)/+0.00,+0.00,-0.01,-0.02,-0.06,-0.10,-0.17,
     1    -0.21,-0.26,-0.33,-0.40,-0.47,-0.54,-0.60,-0.66,-0.72,-0.76,
     2    -0.80,-0.81,-0.82,-0.81/
      data (p0(i,2),i=1,21)/-0.02,-0.16,-0.31,-0.43,-0.54,-0.60,-0.64,
     1    -0.64,-0.64,-0.62,-0.60,-0.56,-0.52,-0.49,-0.45,-0.43,-0.42,
     2    -0.43,-0.45,-0.49,-0.53/
      data (p1(i,2),i=1,21)/+0.00,-0.03,-0.07,-0.12,-0.18,-0.22,-0.31,
     1    -0.34,-0.38,-0.40,-0.41,-0.39,-0.36,-0.30,-0.22,-0.13,-0.01,
     2    +0.12,+0.23,+0.37,+0.45/
      data (p2(i,2),i=1,21)/+0.00,+0.00,-0.01,-0.02,-0.06,-0.10,-0.17,
     1    -0.21,-0.26,-0.33,-0.40,-0.47,-0.54,-0.60,-0.67,-0.72,-0.76,
     2    -0.80,-0.81,-0.82,-0.81/
      data (p0(i,3),i=1,21)/-0.03,-0.16,-0.31,-0.44,-0.53,-0.59,-0.63,
     1    -0.64,-0.63,-0.62,-0.59,-0.55,-0.52,-0.48,-0.45,-0.43,-0.42,
     2    -0.42,-0.44,-0.48,-0.52/
      data (p1(i,3),i=1,21)/+0.00,-0.04,-0.07,-0.13,-0.18,-0.22,-0.31,
     1    -0.35,-0.38,-0.41,-0.41,-0.40,-0.36,-0.30,-0.22,-0.13,-0.01,
     2    +0.12,+0.23,+0.37,+0.45/
      data (p2(i,3),i=1,21)/+0.00,+0.00,-0.01,-0.03,-0.06,-0.10,-0.17,
     1    -0.21,-0.26,-0.33,-0.40,-0.47,-0.54,-0.60,-0.67,-0.72,-0.76,
     2    -0.80,-0.81,-0.82,-0.81/
      data (p0(i,4),i=1,21)/-0.05,-0.17,-0.30,-0.42,-0.52,-0.57,-0.61,
     1    -0.62,-0.61,-0.60,-0.57,-0.53,-0.50,-0.46,-0.43,-0.40,-0.39,
     2    -0.40,-0.42,-0.46,-0.50/
      data (p1(i,4),i=1,21)/+0.00,-0.04,-0.09,-0.14,-0.20,-0.23,-0.32,
     1    -0.36,-0.39,-0.42,-0.42,-0.40,-0.37,-0.31,-0.23,-0.13,-0.02,
     2    +0.11,+0.23,+0.37,+0.44/
      data (p2(i,4),i=1,21)/+0.00,+0.00,-0.01,-0.03,-0.07,-0.10,-0.17,
     1    -0.21,-0.27,-0.33,-0.40,-0.47,-0.54,-0.61,-0.67,-0.72,-0.77,
     2    -0.80,-0.82,-0.82,-0.82/
      data (p0(i,5),i=1,21)/-0.09,-0.18,-0.29,-0.40,-0.49,-0.53,-0.57,
     1    -0.58,-0.57,-0.56,-0.53,-0.49,-0.45,-0.41,-0.38,-0.36,-0.35,
     2    -0.35,-0.37,-0.42,-0.45/
      data (p1(i,5),i=1,21)/+0.00,-0.08,-0.14,-0.18,-0.23,-0.26,-0.34,
     1    -0.38,-0.42,-0.44,-0.44,-0.42,-0.38,-0.32,-0.24,-0.14,-0.03,
     2    +0.10,+0.21,+0.36,+0.43/
      data (p2(i,5),i=1,21)/+0.00,+0.00,-0.02,-0.04,-0.07,-0.10,-0.17,
     1    -0.21,-0.27,-0.33,-0.40,-0.47,-0.54,-0.61,-0.67,-0.72,-0.77,
     2    -0.80,-0.82,-0.82,-0.82/
      data (p0(i,6),i=1,21)/-0.13,-0.20,-0.29,-0.39,-0.46,-0.51,-0.54,
     1    -0.55,-0.54,-0.52,-0.49,-0.45,-0.41,-0.37,-0.34,-0.32,-0.31,
     2    -0.31,-0.33,-0.38,-0.40/
      data (p1(i,6),i=1,21)/+0.00,-0.11,-0.18,-0.22,-0.27,-0.31,-0.37,
     1    -0.41,-0.44,-0.46,-0.46,-0.44,-0.40,-0.34,-0.26,-0.15,-0.04,
     2    +0.09,+0.22,+0.35,+0.41/
      data (p2(i,6),i=1,21)/+0.00,+0.00,-0.02,-0.04,-0.07,-0.11,-0.17,
     1    -0.22,-0.27,-0.34,-0.41,-0.48,-0.55,-0.61,-0.67,-0.73,-0.77,
     2    -0.80,-0.82,-0.82,-0.82/
      data (p0(i,7),i=1,21)/-0.20,-0.25,-0.34,-0.37,-0.41,-0.47,-0.48,
     1    -0.48,-0.47,-0.45,-0.42,-0.38,-0.34,-0.30,-0.27,-0.24,-0.23,
     2    -0.24,-0.26,-0.30,-0.32/
      data (p1(i,7),i=1,21)/+0.00,-0.14,-0.27,-0.29,-0.30,-0.39,-0.42,
     1    -0.46,-0.49,-0.50,-0.50,-0.48,-0.43,-0.37,-0.28,-0.18,-0.05,
     2    +0.08,+0.22,+0.34,+0.38/
      data (p2(i,7),i=1,21)/+0.00,-0.01,-0.04,-0.05,-0.07,-0.14,-0.17,
     1    -0.22,-0.28,-0.35,-0.42,-0.49,-0.56,-0.62,-0.68,-0.74,-0.78,
     2    -0.81,-0.83,-0.83,-0.83/
      data (p0(i,8),i=1,21)/-0.27,-0.30,-0.37,-0.33,-0.41,-0.43,-0.44,
     1    -0.44,-0.42,-0.39,-0.36,-0.32,-0.27,-0.23,-0.20,-0.18,-0.16,
     2    -0.17,-0.19,-0.23,-0.24/
      data (p1(i,8),i=1,21)/+0.00,-0.20,-0.34,-0.30,-0.40,-0.43,-0.47,
     1    -0.51,-0.53,-0.54,-0.54,-0.51,-0.46,-0.39,-0.30,-0.19,-0.07,
     2    +0.08,+0.20,+0.32,+0.34/
      data (p2(i,8),i=1,21)/+0.00,-0.01,-0.06,-0.04,-0.10,-0.13,-0.18,
     1    -0.23,-0.29,-0.36,-0.43,-0.50,-0.57,-0.63,-0.69,-0.74,-0.79,
     2    -0.82,-0.83,-0.83,-0.83/
      data (s0(i,1),i=1,21)/+0.00,-0.31,-0.57,-0.81,-1.02,-1.15,-1.19,
     1    -1.20,-1.19,-1.16,-1.12,-1.06,-0.99,-0.92,-0.87,-0.83,-0.81,
     2    -0.81,-0.86,-0.93,-1.02/
      data (s1(i,1),i=1,21)/+0.00,-0.02,-0.09,-0.19,-0.30,-0.42,-0.51,
     1    -0.60,-0.67,-0.72,-0.73,-0.71,-0.65,-0.56,-0.42,-0.26,-0.05,
     2    +0.17,+0.42,+0.67,+0.86/
      data (s2(i,1),i=1,21)/+0.00,+0.00,-0.01,-0.04,-0.11,-0.21,-0.28,
     1    -0.37,-0.47,-0.59,-0.71,-0.83,-0.96,-1.08,-1.19,-1.29,-1.38,
     2    -1.44,-1.48,-1.50,-1.49/
      data (s0(i,2),i=1,21)/-0.03,-0.29,-0.55,-0.79,-0.99,-1.12,-1.16,
     1    -1.17,-1.16,-1.13,-1.08,-1.02,-0.96,-0.89,-0.83,-0.79,-0.77,
     2    -0.78,-0.82,-0.90,-0.98/
      data (s1(i,2),i=1,21)/+0.00,-0.05,-0.12,-0.21,-0.33,-0.44,-0.53,
     1    -0.62,-0.69,-0.73,-0.74,-0.72,-0.67,-0.57,-0.43,-0.26,-0.06,
     2    +0.17,+0.42,+0.66,+0.85/
      data (s2(i,2),i=1,21)/+0.00,+0.00,-0.01,-0.04,-0.12,-0.21,-0.28,
     1    -0.37,-0.47,-0.59,-0.71,-0.83,-0.96,-1.08,-1.20,-1.30,-1.38,
     2    -1.44,-1.48,-1.50,-1.49/
      data (s0(i,3),i=1,21)/-0.05,-0.29,-0.55,-0.77,-0.98,-1.11,-1.14,
     1    -1.16,-1.15,-1.12,-1.07,-1.01,-0.94,-0.88,-0.82,-0.78,-0.76,
     2    -0.77,-0.81,-0.88,-0.97/
      data (s1(i,3),i=1,21)/+0.00,-0.07,-0.13,-0.22,-0.33,-0.44,-0.54,
     1    -0.62,-0.69,-0.74,-0.75,-0.73,-0.67,-0.57,-0.44,-0.27,-0.06,
     2    +0.16,+0.41,+0.66,+0.85/
      data (s2(i,3),i=1,21)/+0.00,+0.00,-0.01,-0.04,-0.12,-0.21,-0.28,
     1    -0.37,-0.48,-0.59,-0.71,-0.84,-0.96,-1.08,-1.20,-1.30,-1.38,
     2    -1.44,-1.48,-1.50,-1.49/
      data (s0(i,4),i=1,21)/-0.08,-0.30,-0.54,-0.77,-0.95,-1.07,-1.11,
     1    -1.12,-1.11,-1.08,-1.03,-0.97,-0.90,-0.84,-0.78,-0.74,-0.72,
     2    -0.73,-0.77,-0.84,-0.93/
      data (s1(i,4),i=1,21)/+0.00,-0.06,-0.17,-0.26,-0.36,-0.46,-0.56,
     1    -0.64,-0.71,-0.76,-0.77,-0.75,-0.68,-0.59,-0.45,-0.28,-0.07,
     2    +0.16,+0.41,+0.65,+0.83/
      data (s2(i,4),i=1,21)/+0.00,+0.00,-0.02,-0.04,-0.12,-0.21,-0.28,
     1    -0.38,-0.48,-0.59,-0.71,-0.84,-0.97,-1.09,-1.20,-1.30,-1.38,
     2    -1.45,-1.49,-1.50,-1.49/
      data (s0(i,5),i=1,21)/-0.16,-0.33,-0.71,-0.74,-0.90,-1.00,-1.04,
     1    -1.05,-1.04,-1.01,-0.96,-0.90,-0.83,-0.76,-0.70,-0.66,-0.64,
     2    -0.65,-0.69,-0.76,-0.84/
      data (s1(i,5),i=1,21)/+0.00,-0.14,-0.33,-0.34,-0.43,-0.50,-0.61,
     1    -0.69,-0.75,-0.80,-0.80,-0.78,-0.72,-0.61,-0.47,-0.30,-0.09,
     2    +0.14,+0.39,+0.64,+0.81/
      data (s2(i,5),i=1,21)/+0.00,-0.01,-0.05,-0.06,-0.13,-0.20,-0.29,
     1    -0.38,-0.48,-0.60,-0.72,-0.85,-0.97,-1.09,-1.21,-1.31,-1.39,
     2    -1.45,-1.49,-1.50,-1.50/
      data (s0(i,6),i=1,21)/-0.24,-0.37,-0.53,-0.72,-0.88,-0.94,-0.98,
     1    -0.99,-0.97,-0.94,-0.89,-0.82,-0.75,-0.69,-0.63,-0.58,-0.56,
     2    -0.57,-0.61,-0.69,-0.75/
      data (s1(i,6),i=1,21)/+0.00,-0.20,-0.33,-0.40,-0.47,-0.56,-0.66,
     1    -0.74,-0.80,-0.84,-0.84,-0.81,-0.75,-0.64,-0.50,-0.32,-0.11,
     2    +0.12,+0.38,+0.62,+0.78/
      data (s2(i,6),i=1,21)/+0.00,-0.01,-0.03,-0.08,-0.15,-0.21,-0.30,
     1    -0.39,-0.49,-0.61,-0.73,-0.85,-0.98,-1.10,-1.21,-1.31,-1.39,
     2    -1.46,-1.50,-1.51,-1.50/
      data (s0(i,7),i=1,21)/-0.37,-0.46,-0.60,-0.67,-0.80,-0.84,-0.87,
     1    -0.87,-0.86,-0.82,-0.76,-0.69,-0.62,-0.55,-0.49,-0.45,-0.43,
     2    -0.43,-0.48,-0.55,-0.60/
      data (s1(i,7),i=1,21)/+0.00,-0.26,-0.48,-0.52,-0.59,-0.67,-0.76,
     1    -0.83,-0.89,-0.92,-0.91,-0.88,-0.81,-0.69,-0.55,-0.36,-0.15,
     2    +0.09,+0.35,+0.60,+0.71/
      data (s2(i,7),i=1,21)/+0.00,-0.01,-0.07,-0.09,-0.16,-0.23,-0.31,
     1    -0.40,-0.51,-0.62,-0.74,-0.87,-1.00,-1.12,-1.23,-1.33,-1.41,
     2    -1.47,-1.51,-1.52,-1.51/
      data (s0(i,8),i=1,21)/-0.49,-0.55,-0.63,-0.65,-0.73,-0.77,-0.79,
     1    -0.79,-0.76,-0.71,-0.65,-0.58,-0.50,-0.43,-0.37,-0.32,-0.30,
     2    -0.31,-0.35,-0.43,-0.45/
      data (s1(i,8),i=1,21)/+0.00,-0.28,-0.58,-0.60,-0.69,-0.77,-0.86,
     1    -0.92,-0.97,-0.99,-0.99,-0.94,-0.86,-0.74,-0.59,-0.40,-0.18,
     2    +0.07,+0.33,+0.57,+0.64/
      data (s2(i,8),i=1,21)/+0.00,-0.01,-0.09,-0.10,-0.17,-0.23,-0.32,
     1    -0.41,-0.52,-0.64,-0.76,-0.89,-1.01,-1.13,-1.25,-1.34,-1.42,
     2    -1.48,-1.52,-1.53,-1.52/
c23456789012345678901234567890123456789012345678901234567890123456789012
      data (scs0(i,1),i=1,21)/-2.74,-2.72,-2.67,-2.57,-2.45,-2.31,-2.14,
     1    -1.96,-1.78,-1.60,-1.43,-1.27,-1.13,-1.01,-0.92,-0.86,-0.83,
     2    -0.83,-0.87, 0.00,-0.00/
      data (scs1(i,1),i=1,21)/+0.00,-0.21,-0.40,-0.58,-0.74,-0.86,-0.96,
     1    -1.01,-1.03,-1.00,-0.94,-0.84,-0.71,-0.56,-0.38,-0.17, 0.04,
     2    +0.26,+0.48,+0.00,+0.00/
      data (scs2(i,1),i=1,21)/+0.00,-0.01,-0.05,-0.11,-0.19,-0.29,-0.40,
     1    -0.52,-0.64,-0.77,-0.90,-1.02,-1.13,-1.23,-1.32,-1.39,-1.45,
     2    -1.48,-1.50, 0.00, 0.00/
      data (scs0(i,2),i=1,21)/-2.71,-2.69,-2.63,-2.54,-2.42,-2.27,-2.11,
     1    -1.93,-1.75,-1.57,-1.40,-1.24,-1.09,-0.98,-0.88,-0.82,-0.79,
     2    -0.80,-0.83, 0.00, 0.00/
      data (scs1(i,2),i=1,21)/+0.00,-0.21,-0.40,-0.58,-0.74,-0.87,-0.96,
     1    -1.01,-1.03,-1.01,-0.95,-0.85,-0.72,-0.56,-0.38,-0.18, 0.03,
     2    +0.25,+0.47,+0.00,+0.00/
      data (scs2(i,2),i=1,21)/+0.00,-0.01,-0.05,-0.11,-0.19,-0.29,-0.40,
     1    -0.52,-0.64,-0.77,-0.90,-1.02,-1.13,-1.23,-1.32,-1.39,-1.45,
     2    -1.48,-1.50, 0.00, 0.00/
      data (scs0(i,3),i=1,21)/-2.70,-2.68,-2.62,-2.53,-2.41,-2.26,-2.10,
     1    -1.92,-1.74,-1.56,-1.38,-1.22,-1.08,-0.96,-0.87,-0.81,-0.78,
     2    -0.78,-0.82, 0.00, 0.00/
      data (scs1(i,3),i=1,21)/+0.00,-0.21,-0.40,-0.59,-0.74,-0.87,-0.96,
     1    -1.02,-1.03,-1.01,-0.95,-0.85,-0.72,-0.57,-0.38,-0.18, 0.03,
     2    +0.25,+0.47,+0.00,+0.00/
      data (scs2(i,3),i=1,21)/+0.00,-0.01,-0.05,-0.11,-0.19,-0.29,-0.40,
     1    -0.52,-0.64,-0.77,-0.90,-1.02,-1.13,-1.23,-1.32,-1.39,-1.45,
     2    -1.48,-1.50, 0.00, 0.00/
      data (scs0(i,4),i=1,21)/-2.66,-2.64,-2.58,-2.49,-2.37,-2.22,-2.06,
     1    -1.88,-1.70,-1.52,-1.34,-1.18,-1.04,-0.92,-0.83,-0.77,-0.74,
     2    -0.74,-0.78,-0.00,-0.00/
      data (scs1(i,4),i=1,21)/+0.00,-0.21,-0.41,-0.59,-0.75,-0.87,-0.97,
     1    -1.02,-1.04,-1.02,-0.95,-0.86,-0.73,-0.57,-0.39,-0.19, 0.02,
     2    +0.24,+0.46,+0.00,+0.00/
      data (scs2(i,4),i=1,21)/+0.00,-0.01,-0.05,-0.11,-0.19,-0.29,-0.40,
     1    -0.52,-0.64,-0.77,-0.90,-1.02,-1.13,-1.23,-1.32,-1.39,-1.45,
     2    -1.48,-1.50, 0.00, 0.00/
      data (scs0(i,5),i=1,21)/-2.58,-2.56,-2.50,-2.41,-2.29,-2.14,-1.98,
     1    -1.80,-1.62,-1.44,-1.26,-1.10,-0.96,-0.85,-0.75,-0.69,-0.66,
     2    -0.66,-0.70, 0.00,-0.00/
      data (scs1(i,5),i=1,21)/+0.00,-0.21,-0.41,-0.59,-0.75,-0.88,-0.98,
     1    -1.03,-1.05,-1.03,-0.97,-0.87,-0.74,-0.59,-0.41,-0.21, 0.01,
     2    +0.23,+0.45,+0.00,+0.00/
      data (scs2(i,5),i=1,21)/+0.00,-0.01,-0.05,-0.11,-0.19,-0.29,-0.40,
     1    -0.52,-0.65,-0.77,-0.90,-1.02,-1.14,-1.24,-1.32,-1.40,-1.45,
     2    -1.49,-1.51, 0.00, 0.00/
      data (scs0(i,6),i=1,21)/-2.51,-2.49,-2.43,-2.34,-2.21,-2.07,-1.90,
     1    -1.72,-1.54,-1.36,-1.19,-1.03,-0.89,-0.77,-0.68,-0.61,-0.58,
     2    -0.59,-0.62, 0.00, 0.00/
      data (scs1(i,6),i=1,21)/+0.00,-0.21,-0.41,-0.60,-0.76,-0.89,-0.99,
     1    -1.04,-1.06,-1.04,-0.98,-0.89,-0.76,-0.60,-0.42,-0.22,-0.01,
     2    +0.21,+0.43,+0.00,+0.00/
      data (scs2(i,6),i=1,21)/+0.00,-0.01,-0.05,-0.11,-0.19,-0.29,-0.40,
     1    -0.52,-0.65,-0.78,-0.90,-1.03,-1.14,-1.24,-1.33,-1.40,-1.46,
     2    -1.49,-1.51, 0.00, 0.00/
      data (scs0(i,7),i=1,21)/-2.37,-2.35,-2.29,-2.20,-2.08,-1.93,-1.76,
     1    -1.59,-1.40,-1.22,-1.05,-0.89,-0.75,-0.63,-0.54,-0.47,-0.44,
     2    -0.45,-0.48, 0.00, 0.00/
      data (scs1(i,7),i=1,21)/+0.00,-0.22,-0.42,-0.61,-0.77,-0.91,-1.01,
     1    -1.07,-1.09,-1.07,-1.01,-0.92,-0.79,-0.63,-0.45,-0.25,-0.04,
     2    +0.18,+0.40,+0.00,+0.00/
      data (scs2(i,7),i=1,21)/+0.00,-0.01,-0.05,-0.11,-0.19,-0.29,-0.40,
     1    -0.52,-0.65,-0.78,-0.91,-1.03,-1.14,-1.25,-1.33,-1.41,-1.46,
     2    -1.50,-1.52, 0.00, 0.00/
      data (scs0(i,8),i=1,21)/-2.25,-2.23,-2.17,-2.08,-1.96,-1.81,-1.64,
     1    -1.46,-1.28,-1.10,-0.92,-0.76,-0.62,-0.50,-0.41,-0.35,-0.32,
     2    -0.32,-0.36,-0.00,-0.00/
      data (scs1(i,8),i=1,21)/+0.00,-0.22,-0.43,-0.62,-0.79,-0.93,-1.03,
     1    -1.09,-1.11,-1.09,-1.04,-0.94,-0.82,-0.66,-0.48,-0.28,-0.07,
     2    +0.15,+0.37,+0.00,+0.00/
      data (scs2(i,8),i=1,21)/+0.00,-0.01,-0.05,-0.11,-0.19,-0.29,-0.41,
     1    -0.53,-0.66,-0.79,-0.91,-1.04,-1.15,-1.25,-1.34,-1.42,-1.47,
     2    -1.51,-1.53, 0.00, 0.00/
c
c
c     print statements for debugging
c
c     do jj = 1, 21
c       write(6,'(8f6.2)') (p0(jj,ii), ii = 1, 8)
c     end do
c     print*,' '
c     do jj = 1, 21
c       write(6,'(8f6.2)') (p1(jj,ii), ii = 1, 8)
c     end do
c     print*,' '
c     do jj = 1, 21
c       write(6,'(8f6.2)') (p2(jj,ii), ii = 1, 8)
c     end do
c     print*,' '
c     do jj = 1, 21
c       write(6,'(8f6.2)') (s0(jj,ii), ii = 1, 8)
c     end do
c     print*,' '
c     do jj = 1, 21
c       write(6,'(8f6.2)') (s1(jj,ii), ii = 1, 8)
c     end do
c     print*,' '
c     do jj = 1, 21
c       write(6,'(8f6.2)') (s2(jj,ii), ii = 1, 8)
c     end do
c     print*,' '
c     do jj = 1, 21
c       write(6,'(8f6.2)') (scs0(jj,ii), ii = 1, 8)
c     end do
c     print*,' '
c     do jj = 1, 21
c       write(6,'(8f6.2)') (scs1(jj,ii), ii = 1, 8)
c     end do
c     print*,' '
c     do jj = 1, 21
c       write(6,'(8f6.2)') (scs2(jj,ii), ii = 1, 8)
c     end do
c     print*,' '
cccccc
c
      iph = niph
      sde = tsde
      sth = tsth
      rra = trra
      raz = traz
c
c     figure out depth and establish parameters for interpolation
c
      k = 1
      sdi = 0.0
      if (sde .lt. sd(1))  go to 114
      do 110 i=2,8
      k = i-1
      if (sde .lt. sd(i))  go to 112
110   continue
112   if (k .lt. 8)  sdi = (sde-sd(k))/(sd(k+1)-sd(k))
114   continue
      rai = rra/rde
      j = int(rai)
      rai = rai-float(j)
      j = j+1
      j2 = j+1
      if (rra .ge. rmi)  go to 122
      j = 1
      j2 = 1
      go to 124
122   if (rra .lt. rma)  go to 124
      j = 21
      j2 = 21
c
c     P
c
124   if (iph .ne. 1)  go to 126
      p01 = p0(j,k) +sdi*(p0(j,k+1) -p0(j,k))
      p02 = p0(j2,k)+sdi*(p0(j2,k+1)-p0(j2,k))
      p0i = p01+rai*(p02-p01)
      p11 = p1(j,k) +sdi*(p1(j,k+1) -p1(j,k))
      p12 = p1(j2,k)+sdi*(p1(j2,k+1)-p1(j2,k))
      p1i = p11+rai*(p12-p11)
      p21 = p2(j,k) +sdi*(p2(j,k+1) -p2(j,k))
      p22 = p2(j2,k)+sdi*(p2(j2,k+1)-p2(j2,k))
      p2i = p21+rai*(p22-p21)
      go to 999
c
c     S
c
126   if (iph .ne. 2)  go to 128
      p01 = s0(j,k) +sdi*(s0(j,k+1) -s0(j,k))
      p02 = s0(j2,k)+sdi*(s0(j2,k+1)-s0(j2,k))
      p0i = p01+rai*(p02-p01)
      p11 = s1(j,k) +sdi*(s1(j,k+1) -s1(j,k))
      p12 = s1(j2,k)+sdi*(s1(j2,k+1)-s1(j2,k))
      p1i = p11+rai*(p12-p11)
      p21 = s2(j,k) +sdi*(s2(j,k+1) -s2(j,k))
      p22 = s2(j2,k)+sdi*(s2(j2,k+1)-s2(j2,k))
      p2i = p21+rai*(p22-p21)
      go to 999
c
c     ScS
c     --small error corrected 05/13/93
c       p1i terms were not calculated correctly
c
128   if (iph .ne. 3)  go to 900
      p01 = scs0(j,k) +sdi*(scs0(j,k+1) -scs0(j,k))
      p02 = scs0(j2,k)+sdi*(scs0(j2,k+1)-scs0(j2,k))
      p0i = p01+rai*(p02-p01)
      p11 = scs1(j,k) +sdi*(scs1(j,k+1) -scs1(j,k))
      p12 = scs1(j2,k)+sdi*(scs1(j2,k+1)-scs1(j2,k))
      p1i = p11+rai*(p12-p11)
      p21 = scs2(j,k) +sdi*(scs2(j,k+1) -scs2(j,k))
      p22 = scs2(j2,k)+sdi*(scs2(j2,k+1)-scs2(j2,k))
      p2i = p21+rai*(p22-p21)
      go to 999
c
c     errror return
c
900   continue
      te = 9999.0
      return
c
c     put it all together
c     
999   continue
ccccc lsg mod 05/13/93
ccccc - not that it makes a difference
c
c     This is Lane's original code
c
      thg = atan(ell*tan(sth/radi))
      cla = tpi/4.0 - thg
c
      sth = sin(cla)
      cth = cos(cla)
      azr = raz/radi
      te = 0.5*(3.0*cth*cth-1.0)*p0i+sqrt(3.0)*sth*(cth*cos(azr)*p1i+
     1     0.5*sth*cos(2.0*azr)*p2i)
c
c     My variation - they give the same answer
c
c     e = 1.0/298.25
c     slatra = sth/radi
c     w = sin(slatra)
c     s = ((2.-e)*w +4.*e*(w**3))*e*cos(slatra)
c     cla = 0.25*tpi - slatra + s
c     azr = raz/radi
c     cth = cos(cla)
c     sth = sin(cla)
c     c2th = cos(2.0*cla)
c     s2th = sin(2.0*cla)
c     te = 0.25*(1.0 + 3.0*c2th)*p0i 
c    1   + 0.5*sqrt(3.0)*(s2th*cos(azr)*p1i+sth*sth*cos(2.0*azr)*p2i)
ccccc lsg end mod 
c
      return
      end

